package org.zfes.snowier.zbss.xzy.router.solution;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.solution.model.Algorithm;
import org.zfes.snowier.zbss.xzy.biz.solution.service.IAlgorithmService;
import org.zfes.snowier.core.data.SelectVo;
@Controller 
@RequestMapping("/manger/algorithm")
public class AlgorithmController implements BaseController {

	
	@Autowired
	private IAlgorithmService algorithmService;
	
	//@RequiresPermissions(value="algorithm:loadAlgorithmDataSet",desc="算法管理列表")
    @RequestMapping(value="/loadAlgorithmDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithmDataSet( @RequestParam Map<String,Object> params){
	    DataSet dataSet=  algorithmService.loadAlgorithmDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="algorithm:createAlgorithm",desc="算法管理添加")
    @RequestMapping(value="/createAlgorithm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object createAlgorithm( Algorithm algorithm){
		algorithmService.createAlgorithm(algorithm);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="algorithm:loadAlgorithm",desc="算法管理加载")
    @RequestMapping(value="/loadAlgorithm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithm(Long id){
		Optional<Algorithm> ops = algorithmService.loadAlgorithmById(id);
		return ajaxQuery("algorithm",ops);
    }
	
	//@RequiresPermissions(value="algorithm:updateAlgorithm",desc="算法管理更新")
    @RequestMapping(value="/updateAlgorithm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object updateAlgorithm(Algorithm algorithm){
		algorithmService.updateAlgorithm(algorithm);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="algorithm:deletAlgorithm",desc="算法管理删除")
    @RequestMapping(value="/setAlgorithmStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object deleteAlgorithm(Long id,Byte status){
		algorithmService.setAlgorithmStatus(id, status);
		return ajaxDoneSuccess("数据操作成功 ");
    }


    @RequestMapping(value="/loadAlgorithmSelectVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithmSelectVo(){
		 List<SelectVo>  ops = algorithmService.loadAlgorithmSelectVo("");
		return ajaxQuery("selectVo",ops);
    }
    
    @RequestMapping(value="/loadAllAlgorithm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAllAlgorithm(String name,Integer maxCount){
    	List<Algorithm>  algorithmList = algorithmService.loadAlgorithmByName(name,maxCount,Byte.valueOf("1"));
		return ajaxQuery("algorithmList",algorithmList);
    }
    
    
}